package com.venue.hjt.venueclass.utlis;

import android.util.Log;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by xqx on 2017/11/7
 * 时间工具类.
 */

public class ClassCalendar {
    static int year;
    static int month;
    static int day;
    static int hour;
    static int minuts;
    static int secno;
    static Calendar c;
    static String[] weekDays1 = {"(周日)", "(周一)", "(周二)", "(周三)", "(周四)", "(周五)", "(周六)"};
    static String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
    public static String getStringDay(){
        c=Calendar.getInstance();
        year= c.get(Calendar.YEAR);
        month=c.get(Calendar.MONTH);
        day=c.get(Calendar.DAY_OF_MONTH);
        return year+"年"+(month+1)+"月"+day+"日 "+weekDays[ClassCalendar.getWeekDays()];
    }
    public static String getStringDay1(){
        String strmonth="";
        String strday="";
        c=Calendar.getInstance();
        month=c.get(Calendar.MONTH)+1;
        day=c.get(Calendar.DAY_OF_MONTH);
        strmonth= month<10?"0"+month:month+"";
        strday= day<10?"0"+day:day+"";
        return strmonth+"-"+strday+" "+weekDays[ClassCalendar.getWeekDays()];
    }
    //获取日期
    public static String getStringtHour(){
        String strhour="";
        String strsen="";
        String strmon="";
        c=Calendar.getInstance();
        hour=c.get(Calendar.HOUR_OF_DAY);
        minuts=c.get(Calendar.MINUTE);
        secno=c.get(Calendar.SECOND);
        strhour= hour<10?"0"+hour:hour+"";
        strmon= minuts<10?"0"+minuts:minuts+"";
        strsen= secno<10?"0"+secno:secno+"";
        return ""+strhour+":"+strmon+":"+strsen;
    }
    //获取日期
    public static String getIntDay(){
        c=Calendar.getInstance();
        year= c.get(Calendar.YEAR);
        month=c.get(Calendar.MONTH);
        day=c.get(Calendar.DAY_OF_MONTH);
        return ""+year+(month+1)+day;
    }
    //获取日期
    public static String getIntDayVenue(){
        String strmonth="";
        String strday="";
        String strhour="";
        String strmon="";
        c=Calendar.getInstance();
        year= c.get(Calendar.YEAR);
        month=c.get(Calendar.MONTH)+1;
        day=c.get(Calendar.DAY_OF_MONTH);
        hour=c.get(Calendar.HOUR_OF_DAY);
        strhour= hour<10?"0"+hour:hour+"";
        minuts=c.get(Calendar.MINUTE);
        strmon= minuts<10?"0"+minuts:minuts+"";
        strmonth= month<10?"0"+month:month+"";
        strday= day<10?"0"+day:day+"";
        return ""+year+"/"+strmonth+"/"+strday+" "+strhour+":"+strmon;
    }
    //获取日期
    public static String getIntDayVenue1(){
        String strmonth="";
        String strday="";
        String strhour="";
        String strmon="";
        c=Calendar.getInstance();
        year= c.get(Calendar.YEAR);
        month=c.get(Calendar.MONTH)+1;
        day=c.get(Calendar.DAY_OF_MONTH);
        hour=c.get(Calendar.HOUR_OF_DAY);
        strhour= hour<10?"0"+hour:hour+"";
        minuts=c.get(Calendar.MINUTE);
        strmon= minuts<10?"0"+minuts:minuts+"";
        strmonth= month<10?"0"+month:month+"";
        strday= day<10?"0"+day:day+"";
        return ""+year+"/"+strmonth+"/"+strday;
    }
    public static String getOldDate(int distanceDay) {
        SimpleDateFormat dft = new SimpleDateFormat("MM-dd");
        Date beginDate = new Date();
        Calendar date = Calendar.getInstance();
        date.setTime(beginDate);
        date.set(Calendar.DATE, date.get(Calendar.DATE) + distanceDay);
        Date endDate = null;
        try {
            endDate = dft.parse(dft.format(date.getTime()));
        } catch (ParseException e) {
            e.printStackTrace();
        }
//        LogUtil.d("前7天==" + dft.format(endDate));
        return dft.format(endDate);
    }
    public static String getOldDate1(int distanceDay) {
        SimpleDateFormat dft = new SimpleDateFormat("yyyy-MM-dd");
        Date beginDate = new Date();
        Calendar date = Calendar.getInstance();
        date.setTime(beginDate);
        date.set(Calendar.DATE, date.get(Calendar.DATE) + distanceDay);
        Date endDate = null;
        try {
            endDate = dft.parse(dft.format(date.getTime()));
        } catch (ParseException e) {
            e.printStackTrace();
        }
//        LogUtil.d("前7天==" + dft.format(endDate));
        return dft.format(endDate);
    }

    public static String getHourVenue(){
        String strhour="";
        String strmon="";
        String strsen="";
        c=Calendar.getInstance();

        hour=c.get(Calendar.HOUR_OF_DAY);
        strhour= hour<10?"0"+hour:hour+"";
        minuts=c.get(Calendar.MINUTE);
        strmon= minuts<10?"0"+minuts:minuts+"";
        secno=c.get(Calendar.SECOND);
        strsen= secno<10?"0"+secno:secno+"";
        return strhour+":"+strmon+":"+strsen;
    }
    public static String getCardtime(){
        String strmonth="";
        String strday="";
        String strhour="";
        String strsen="";
        String strmon="";
        c=Calendar.getInstance();
        year= c.get(Calendar.YEAR);
        month=c.get(Calendar.MONTH)+1;
        day=c.get(Calendar.DAY_OF_MONTH);
        hour=c.get(Calendar.HOUR_OF_DAY);
        strmonth= month<10?"0"+month:month+"";
        strday= day<10?"0"+day:day+"";
        strhour= hour<10?"0"+hour:hour+"";
        minuts=c.get(Calendar.MINUTE);
        strmon= minuts<10?"0"+minuts:minuts+"";
        secno=c.get(Calendar.SECOND);
        strsen= secno<10?"0"+secno:secno+"";
        return ""+year+""+strmonth+strday+strhour+strmon+strsen;
    }
    public static String getStringMinuts(){
        String strmonth="";
        String strday="";
        String strhour="";
        String strminuts="";
        c=Calendar.getInstance();
        year= c.get(Calendar.YEAR);
        month=c.get(Calendar.MONTH)+1;
        day=c.get(Calendar.DAY_OF_MONTH);
        strmonth= month<10?"0"+month:month+"";
        strday= day<10?"0"+day:day+"";
        hour=c.get(Calendar.HOUR_OF_DAY);
        minuts=c.get(Calendar.MINUTE);
        if (hour<10){
            strhour="0"+hour;
        }else{
            strhour=hour+"";
        }
        if (minuts<10){
            strminuts="0"+minuts;
        }else{
            strminuts=minuts+"";
        }
        return ""+year+strmonth+strday+strhour+strminuts;
    }
    public static String getStringDays(String hour,String minuts){
        String strmonth="";
        String strday="";
        c=Calendar.getInstance();
        year= c.get(Calendar.YEAR);
        month=c.get(Calendar.MONTH)+1;
        day=c.get(Calendar.DAY_OF_MONTH);
        strmonth= month<10?"0"+month:month+"";
        strday= day<10?"0"+day:day+"";
        return ""+year+strmonth+strday+hour+minuts;
    }
    //获取时间
    public static String getIntTimes(){
        c=Calendar.getInstance();
        hour=c.get(Calendar.HOUR_OF_DAY);
        minuts=c.get(Calendar.MINUTE);
        String strmon="";
        strmon= minuts<10?"0"+minuts:minuts+"";
        return hour+":"+strmon;
    }
    public static String getStringVenueOrder(int i) throws Exception {
        String week="今天";
        String strmonth="";
        String strday="";
        if (i==0){
            String weekDay = weekDays1[getWeekDays()];
            return week+weekDay;
        }else{
            String oldDate = getOldDate(i);
//            c=Calendar.getInstance();
//            year= c.get(Calendar.YEAR);
//            month=c.get(Calendar.MONTH)+1;
//            day=c.get(Calendar.DAY_OF_MONTH)+i;
//            strmonth= month<10?"0"+month:month+"";
//            strday= day<10?"0"+day:day+"";
//            int i1 = APPUtlis.dayForWeek("" + year + "-" + strmonth + "-" + strday);
//            if (i1==7){
//                i1=0;
//            }
//            Log.e("ATG","" + year + "-" + strmonth + "-" + strday+"wc  "+i1);
//            String weekDay = weekDays1[i1];
            return oldDate+""+strday+getWeekByDateStr( getOldDate1(i));
        }
    }
    public static String getStringVenueOrderComplaint(int i) throws Exception {
        String week="今天";
        String strmonth="";
        String strday="";
        if (i==0){
//            String weekDay = weekDays1[getWeekDays()];
            return week;
        }else{
            String oldDate = getOldDate(-i);
//            c=Calendar.getInstance();
//            year= c.get(Calendar.YEAR);
//            month=c.get(Calendar.MONTH)+1;
//            day=c.get(Calendar.DAY_OF_MONTH)-i;
//            strmonth= month<10?"0"+month:month+"";
//            strday= day<10?"0"+day:day+"";
////            int i1 = APPUtlis.dayForWeek("" + year + "-" + strmonth + "-" + strday);
////            if (i1==7){
////                i1=0;
////            }
////            Log.e("ATG","" + year + "-" + strmonth + "-" + strday+"wc  "+i1);
////            String weekDay = weekDays1[i1];
//            return strmonth+"-"+strday;
            return oldDate+""+strday+getWeekByDateStr( getOldDate1(-i));
        }
    }
    public static String getStringVenueOrderComplaint1(int i){
        String strmonth="";
        String strday="";
        c=Calendar.getInstance();
        year= c.get(Calendar.YEAR);
        month=c.get(Calendar.MONTH)+1;
        day=c.get(Calendar.DAY_OF_MONTH)-i;
        strmonth= month<10?"0"+month:month+"";
        strday= day<10?"0"+day:day+"";

        return ""+year+"-"+strmonth+"-"+strday;
    }
    public static String getStringVenueOrderComplaint2(){
        String strmonth="";
        String strday="";
        c=Calendar.getInstance();
        year= c.get(Calendar.YEAR);
        month=c.get(Calendar.MONTH)+1;
        day=c.get(Calendar.DAY_OF_MONTH);
        strmonth= month<10?"0"+month:month+"";
        strday= day<10?"0"+day:day+"";

        return ""+year+""+strmonth+""+strday;
    }
    public static String getStringVenueOrder1(int i){
        String strmonth="";
        String strday="";
        c=Calendar.getInstance();
        year= c.get(Calendar.YEAR);
        month=c.get(Calendar.MONTH)+1;
        day=c.get(Calendar.DAY_OF_MONTH)+i;
        strmonth= month<10?"0"+month:month+"";
        strday= day<10?"0"+day:day+"";

        return ""+year+"-"+strmonth+"-"+strday;
    }
    //获取周几
    public static int getWeekDays(){
        c=Calendar.getInstance();
        return c.get(Calendar.DAY_OF_WEEK)-1;
    }   //获取周几
    public static int getWeekDays1(){
        c=Calendar.getInstance();
        int week = c.get(Calendar.DAY_OF_WEEK) - 1;
        if (week==0){
            week=7;
        }
        return week ;
    }
    public static String getHour(){
        String strhour="";
        String strmon="";
        c=Calendar.getInstance();

        hour=c.get(Calendar.HOUR_OF_DAY);
        strhour= hour<10?"0"+hour:hour+"";
        minuts=c.get(Calendar.MINUTE);
        strmon= minuts<10?"0"+minuts:minuts+"";
        return strhour+"."+strmon;
    }
    public static String getWeekByDateStr(String strDate)
    {
        int year = Integer.parseInt(strDate.substring(0, 4));
        int month = Integer.parseInt(strDate.substring(5, 7));
        int day = Integer.parseInt(strDate.substring(8, 10));

        Calendar c = Calendar.getInstance();

        c.set(Calendar.YEAR, year);
        c.set(Calendar.MONTH, month - 1);
        c.set(Calendar.DAY_OF_MONTH, day);

        String week = "";
        int weekIndex = c.get(Calendar.DAY_OF_WEEK);

        switch (weekIndex)
        {
            case 1:
                week = "周日";
                break;
            case 2:
                week = "周一";
                break;
            case 3:
                week = "周二";
                break;
            case 4:
                week = "周三";
                break;
            case 5:
                week = "周四";
                break;
            case 6:
                week = "周五";
                break;
            case 7:
                week = "周六";
                break;
        }
        return week;
    }
    public static String getStringWeekDays(){
        return weekDays[ClassCalendar.getWeekDays()];
    }
}
